<?php
header('content-type:text/html;charset=utf-8'); 

//decodeURIComponent後端解碼
// $DT=$_GET["DT"];//日期2018-3-10 09:43:05注釋:這個已經取消,自動生成今天的即可
// echo $DT."</br>";
$GX=$_GET["GongXu"];//工序
$BB=$_GET["BanBie"];//班別
$DT=date("Y-m-d");//"2018-03-01";//date("Y-m-d")
// echo $GX."</br>";
//echo $BB."</br>";
// echo $DT."</br>";

//从数据库中获取数据，为了节省内存，不要把数据一次性读到内存，从句柄中一行一行读即可 
$conn=mysql_connect("127.0.0.1:3306","root","tdled2018");
if (!$conn){
	die('Could not connect: ' . mysql_error());
}

mysql_select_db("tddb", $conn);

mysql_query("set character set 'utf8'");//读库 

mysql_query("set names 'utf8'");//写库 

//`GongXu`,`BanBie`,
//原語句備份
//$sql = "SELECT `JiTai`, `GongDan`, `ChanPinLeiXing`, `ChanPinXiLie`,`ChanPinXingHao`, `JiHuaQTY`, `JiHuaTime` FROM `m_pl_temp` WHERE 1";//`GongXu` = ".$GX." and `RiQi` =".$DT

$sql = 
"SELECT 
	`ID`,
	`DingDanHao`,
	`GongXu`,
	`RiQi`,
	`BanBie`,
	`ChanPinXingHao`,
	`ChanPinLeiXing`,
	`JiTai`,
	`GongDan`,
	`ChanPinXiLie`,
	`CaoZuoYuan`,
	`JiHuaQTY`,
	`ShiJiQTY`,
	`JiHuaTime`,
	`ShiJiTime`,
	`DaiJiTime`,
	`DianJianTime`,
	`HuanDanTime`,
	`HuanHaoCaiTime`,
	`QingYeJuTime`,
	`ShouJianTime`,
	`TiaoJiTime`,
	`GongChengShiYangiTime`,
	`GuZhangTime`,
	`PinZhiYiChangTime`,
	`DaiLiaoTime`,
	`ShuiDianQiYiChangiTime`,
	`QiTaJiHuaWaiTingJiTime`,
	`WeiDaChengYuanYinBeiZhu`,
	`ZhengChangTime`,
	`KeLiYongTime`,
	`TingJiTime`,
	`LiLunTime`,
	`UPH`,
	`ShengChanXiaoLv`,
	`JiaDongLv`,
	`JiHuaDaChengLv`,
	`ChanNengShiFouDaCheng`
FROM 
	`m_d_temp` ";
$WHERE = "WHERE `RiQi` ='".$DT."'";
	if ($GX=="" and $BB==""){
		$sql .= $WHERE;
	}else{
		$sql .= $WHERE."and `GongXu` = '".$GX."' and `BanBie` ='".$BB."'";
	};
//"WHERE `RiQi` ='".$DT."'";//`GongXu` = '".$GX."' and `BanBie` ='".$BB."' and `RiQi` ='".$DT."'";

//echo $sql."</br>";

$result = mysql_query($sql); 

$dbdata = array();

//Fetch into associative array
  while ( $row = mysql_fetch_row($result))  {
	//echo json_encode($row)."</br>";
	$dbdata[]=$row;
  }

//Print array in JSON format
 echo json_encode($dbdata);
?>
